package top.aiprogram.login.controller;

import top.aiprogram.login.Teacher;
import top.aiprogram.login.service.LoginService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String pwd = request.getParameter("pwd");
        LoginService loginService = new LoginService();
        Teacher teacher =  loginService.checkLogin(username,pwd);
        if(teacher!=null){
            //登录验证通过  跳进系统进入学生列表界面  设置session
            request.getSession().setAttribute("userInfo",teacher);
            request.getRequestDispatcher("WEB-INF/view/studentList.jsp").forward(request,response);
        }else {
            request.getRequestDispatcher("login.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
